const NodeRSA = require('node-rsa');
function createKey() {
  const key = new NodeRSA({ b: 8 * 100 }); // 生成2048位的密钥
  // const str = key.sign('123');
  // console.log(str);
  const publicPem = key.exportKey('pkcs8-public-pem'); // 公钥
  const privatePem = key.exportKey('pkcs8-private-pem');// 私钥
  // console.log('公钥:', publicKey);
  // console.log('私钥:', privateKey);
  const signed = key.sign('123');
  console.log(key.verify('123', signed))
  return {
    publicPem,
    privatePem,
  };
}
const { publicPem, privatePem } = createKey();
console.log(publicPem, privatePem)

const privatekey = new NodeRSA();
privatekey.importKey(privatePem, 'pkcs8-private-pem');
const aa = privatekey.sign(Buffer.from('123'));
console.log(aa);
var publickey = new NodeRSA();
publickey.importKey(publicPem, 'pkcs8-public-pem');
var result = publickey.verify(Buffer.from('123'), aa);
console.log(result);